package org.itstack.demo.netty.server;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;

public class NettyServer { // 7397
    public static void main(String[] args) throws InterruptedException{
        EventLoopGroup group = new NioEventLoopGroup();

        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(group)
                    .channel(NioDatagramChannel.class)
                    .option(ChannelOption.SO_BROADCAST, true)
                    .option(ChannelOption.SO_RCVBUF, 2048*1024) // 设置UDP读缓冲区为2M
                    .option(ChannelOption.SO_SNDBUF, 1024*1024) // 设置UDP写缓冲区为1M
                    .handler(new MyChannelInitializer());

            ChannelFuture channelFuture = bootstrap.bind(7397).sync();
            System.out.println("server ...... !");
            channelFuture.channel().closeFuture().sync();

        } finally {
            group.shutdownGracefully();
        }


    }
}
